import 'package:flutter/material.dart';
import 'package:flutter_douban/config/app_colors.dart';
import 'package:flutter_douban/main_page/collect/page/collection_class_page.dart';
import 'package:flutter_douban/main_page/collect/page/collection_cook_page.dart';
import 'package:flutter_douban/main_page/collect/page/collection_note_page.dart';
import 'package:flutter_douban/tool_views/my_underline_tabIndicator.dart';

class CollectPage extends StatefulWidget {
  const CollectPage({Key? key}) : super(key: key);

  @override
  _CollectPageState createState() => _CollectPageState();
}

const List<Tab> _tabs = [
  Tab(text: '  菜谱  '),
  Tab(text: '  笔记  '),
  Tab(text: '  课程  '),
];

final List<Widget> _tabaContent = [
  CollectionCookPage(),
  CollectionNotePage(),
  CollectionClassPage(),
];

class _CollectPageState extends State<CollectPage> with TickerProviderStateMixin{
  late TabController _tabController;
  final PageController pageController = new PageController();
  final ScrollController scrollController = new ScrollController();

  /// 初始化方法 请求数据
  @override
  void initState() {
    super.initState();

    _tabController = TabController(
      length: _tabs.length,
      vsync: this,
      initialIndex: 0, // 默认选中哪一个
    );

    _tabController.addListener(() {
      _tabController.index;
      print('切换了item');
    });
  }

  @override
  void dispose() {
    // 释放对象
    _tabController.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: TabBar(
          tabs: _tabs,
          controller: _tabController,
          isScrollable: true,
          indicator: MyUnderlineTabIndicator(
              borderSide: BorderSide(
                  width: 5.0, color: AppColors.yellow)),
          onTap: (index) {
          },
        ),
      ),
      body: Container(
        child: TabBarView(
          children: _tabaContent,
          controller: _tabController,
        ),
      ),
    );
  }
}
